package com.FH.applyFrom.work_week_plan;

import com.FH.organization.Attachment.AttachmentPullDTO;
import com.FH.util.ResultDTO;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 * Created by Administrator on 2017/11/22 0022.
 */
@Path("/workWeekPlan")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class WorkWeekPlanResource {

    @EJB
    WorkWeekPlanDAO workWeekPlanDAO;

    @GET
    @Path("/{search}&{page}&{size}")
    public ResultDTO getWorkWeekPlanInfo(@PathParam("search")String search, @PathParam("page")String page, @PathParam("size")String size){
        //添加分页查询
        if(page==null||"".equals(page)){
            page = "1";//从第一页查起
        }
        if(size==null||"".equals(size)){
            size = "10";//默认每页10行
        }
        return workWeekPlanDAO.getWorkWeekPlanInfo(search,page,size);
    }

    /**
     * 根据日期导出全部部门计划
     * @param
     * @return
     */
    @GET
    @Path("/download/{start_time}&{end_time}")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO downloadExcel(@PathParam("start_time")String start_time,@PathParam("end_time")String end_time){
        return workWeekPlanDAO.downloadPlanExcel(start_time,end_time);
    }

    /**
     * 下载Excel表
     * @param
     * @return
     */
    @GET
    @Path("/download/{org_id}&{start_time}&{end_time}")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO downloadExcel(@PathParam("org_id")String org_id, @PathParam("start_time")String start_time, @PathParam("end_time")String end_time){
        return workWeekPlanDAO.downloadExcel(org_id,start_time,end_time);
    }

    /**
     * 上传Excel表
     * @param
     * @return
     */
    @POST
    @Path("/upload")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO uploadExcel(AttachmentPullDTO attachmentPullDTO){
        return workWeekPlanDAO.uploadExcel(attachmentPullDTO);
    }


    /**
     * 解析导入的Excel表
     * @param
     * @return
     */
    @POST
    @Path("/poiExcel")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO poiExcel(AttachmentPullDTO attachmentPullDTO){
        return workWeekPlanDAO.poiExcel(attachmentPullDTO);
    }

    /**
     * 批量添加
     * @param workWeekPlanPullDTO
     * @return
     */
//    @POST
//    @Path("/addSalaryBillList")
//    @Consumes(MediaType.APPLICATION_JSON)
//    public ResultDTO addWorkWeekPlanInfo(WorkWeekPlanPullDTO workWeekPlanPullDTO){
//        return workWeekPlanDAO.addWorkWeekPlanInfo(workWeekPlanPullDTO);
//    }

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO addWorkWeekPlanInfo(WorkWeekPlanPullDTO workWeekPlanPullDTO){
        return workWeekPlanDAO.addWorkWeekPlanInfo(workWeekPlanPullDTO);
    }

    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO updateWorkWeekPlanInfo(WorkWeekPlanPullDTO workWeekPlanPullDTO){
        return workWeekPlanDAO.updateWorkWeekPlanInfo(workWeekPlanPullDTO);
    }

    @PUT
    @Path("/delete")
    @Consumes(MediaType.APPLICATION_JSON)
    public ResultDTO deleteWorkWeekPlanInfo(WorkWeekPlanPullDTO workWeekPlanPullDTO){
        return workWeekPlanDAO.deleteWorkWeekPlanInfo(workWeekPlanPullDTO);
    }
}
